<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	</head>
	<body>
		<div id="app">
			{{fullName}}
			<p>{{fullName2}}</p>
		</div>	
		<script type="text/javascript">
			/**
			 * vue 2.6.0+ 
			 * 缩写语法
			 */
			let app=new Vue({
				el:'#app',
				data:{
					firstName:'Foo',
					lastName:'Bar',
					//fullName:'Foo Bar'
				},
				methods:{
					click1:function(){
						
					}
				},
				//这种方式比下面watch要好得多  计算属性默认只有getter 可以自己设置setter
				computed:{
					fullName:function(){
						return this.firstName+' '+this.lastName;
					},
					fullName2:{
						get:function(){
							return this.firstName+' '+this.lastName;
						},
						set:function(newValue){
							let names=newValue.split(' ');
							this.firstName=names[0];
							this.lastName=names[1];
						}
					}
				},
				/*
				//监控属性变化，可以换另外一种计算属性computed
				watch:{
					firstName:function(val){
						this.fullName=val+' '+this.lastName;
					},
					lastName:function(val){
						this.fullName=this.firstName+' '+val;
					}
				} */
			});
			app.fullName2='hh kk';
		</script>	
		<style>
			.red{color: red;}
			.blue{color: blue;font-size: 100px;}
		</style>
	</body>
</html>
